var initData = function(num){
	var url = base+"/projectCenter/designcell/constantData/";
	var param = {
			page_num:num,
			page_size:"10",
            project_id:project_id,
            design_cell_id:design_cell_id
	};
	$.ajax({
        url: url,
        data: param,
        success: function (data, textStatus, jqXHR) {
        	//debugger
        	if(data != null){
	        	var pageCount = data.dataList.pager.pageCount;
	        	var dataObj ={
	        			"list":data.dataList.list,
	         			"dataTool":{
	         				"title":{
                                //"id":"id",
                                "constant_table_code":"常量集编号",
                                "constant_table_name": "常量集名称",
                                "constant_table_version_number":"常量集版本号",
                            	"operation":"操作"
	            			},
	            			"titleCheckbox":false,
							"btn":[{"event":"qyOne","name":"取用"}]
						}
		  		};
	        	showPageTable('view', dataObj,num,pageCount,"initData");
        	}
        },
        error: function () {
        }
    });
	
}

var showButton = function(){
	var button_html = ' <div class="btn-team">'+
		              ' <button class="btn btn-default" id="qyConstantIs" onclick="qyBatch()">一键取用</button>';
	$(".btn-team").remove();
	$("#div_content").prepend(button_html);
}

var qyOne = function(obj) {
    var constant_table_code = obj.constant_table_code;
    var data_id = $.trim($("#data_id").val());
    var url = base+"/projectCenter/designcell/takeConstant/"+project_id+"/"+design_cell_id+"/"+constant_table_code+"/"+data_id;
    $.get(url, function(result){
   	   $(".layui-show").html("");
   	   $(".layui-show").html(result);
       });
}


var qyBatch = function(){
	//debugger
    layer.confirm('确认一键取用?',{btn : [ '确定', '取消' ]},function(index){
        layer.close(index);
        $.ajax({
            url:base+"/projectCenter/designcell/takeConstantIS/"+project_id+"/"+design_cell_id,
            data:{},
            success:function(data,status){
                if(data!=""&&data!=null){
                    if(data.statusCode == 0){
                        layer.msg('一键取用成功', {icon: 1,time:2000});
                    }else{
                        layer.msg(data.message, {icon: 2,time:2000});
                    }
                }else{
                    layer.msg('一键取用失败!', {icon: 2,time:2000});
                }
                initData(1);
            }
        });
    });
}

$(document).ready(function(){
	showButton();
	initData(1);
});
